package gui.screens;

import gui.CanvasManager;

import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import application.MainController;

/**
 * This class is the screen with the details of the hunter.
 * @author Sandra Mayer
 *
 */
public class HunterInfoScreen extends Canvas implements CommandListener {
	private String info = "Here is your personal info";
	private String hunterName = "Your Name: ";
	private String hunterPoints = "Your Kills: ";
	private String gameName = "Game: ";
	private Image backgroundImg;
	private Command okCmd;
	private static HunterInfoScreen instance;
	
	/**
	 * Private Constructor.
	 *
	 */
	private HunterInfoScreen() {	
		okCmd = new Command("Ok", Command.OK, 0);
		this.addCommand(okCmd);
		this.setCommandListener(this);
		try {
			backgroundImg = Image.createImage("/mainWhite.jpg");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Returns the instance of the screen.
	 * @return the instance of the screen
	 */
	public static HunterInfoScreen getInstance() {
		if (instance == null) {
			instance = new HunterInfoScreen();
		}
		CanvasManager.setCurScreen(instance);
		return instance;
	}

	/**
	 * Paints the screen.
	 */
	protected void paint(Graphics g) {
		g.setColor(0xffffff);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.translate((getWidth() - backgroundImg.getWidth()) / 2,
				(getHeight() - backgroundImg.getHeight()) / 2);

		g.drawImage(backgroundImg, 0, 0, Graphics.TOP | Graphics.LEFT);

		g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD,
				Font.SIZE_MEDIUM));
		g.setColor(0x000000);
		
		g.drawString(info, 15, 60, Graphics.LEFT | Graphics.TOP);
		
		g.drawString(hunterName, 15, 80, Graphics.LEFT | Graphics.TOP);
		g.drawString(hunterPoints, 15, 105, Graphics.LEFT | Graphics.TOP);
		g.drawString(gameName, 15, 130, Graphics.LEFT | Graphics.TOP);
		g.drawString("Position: ", 15, 155, Graphics.LEFT | Graphics.TOP);
		  
		g.drawString(MainController.getInstance().getHunter().getName(), 140, 80, Graphics.LEFT | Graphics.TOP);
		g.drawString(Integer.toString(MainController.getInstance().getHunter().getKills()), 140, 105, Graphics.LEFT | Graphics.TOP);
		g.drawString(MainController.getInstance().getGame().getName(), 140, 130, Graphics.LEFT | Graphics.TOP);
		g.drawString(MainController.getInstance().getHunter().getPos().getX() + " / " + MainController.getInstance().getHunter().getPos().getY(), 140, 155, Graphics.LEFT | Graphics.TOP);
	}

	/**
	 * Does the command action.
	 */
	public void commandAction(Command cmd, Displayable arg1) {
		if (cmd == okCmd) {
			CanvasManager.showCanvas();
		}
	}

}
